const http = require('http')
const fs = require('fs')
const path = require('path')

var filePath = path.join(__dirname,"/data.json")

http.createServer((req,res)=>{
    var str = ''
    req.on('data',(chunk)=>{
        str += chunk
    })
    req.on('end',()=>{
        var obj = JSON.parse(str)
        var dataObj = JSON.parse(fs.readFileSync(filePath))
        var list = dataObj.userList
        var flag = 0
        for(var i = 0;i<list.length;i++){
            if(obj.userName==list[i].userName && obj.pwd == list[i].pwd){
                console.log("登录成功")
                break
            }else{
                flag++
            }
        }
        if(flag==list.length){
            console.log("用户名或密码不正确")
        }
    })
}).listen(8081)